package com.example.springboot.controller;

import com.example.springboot.entity.Application;
import com.example.springboot.entity.Approval;
import com.example.springboot.mapper.ApprovalMapper;
import com.example.springboot.mapper.UserMapper;
import com.example.springboot.service.ApprovalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/approvals")
public class ApprovalController {
    @Autowired
    private ApprovalMapper approvalMapper;

    @Autowired
    private ApprovalService approvalService;

    @Autowired
    private UserMapper userMapper;

    //用get请求查询数据库信息
    @GetMapping
    public List<Approval> findAll(){
        return approvalMapper.findAll();//查询所有数据
    }

    //用post请求对数据库数据进行增加和修改
    @PostMapping
    public Integer save(@RequestBody Approval approval){
        approval.setApproverId(userMapper.selectId(approval.getApproverName()));
        return approvalService.save(approval);//往数据库插入或更新数据
    }


}
